/**********************************************************************
 Copyright (C) 2011 Jaakko Vuori

 This file is part of ShredMate.
 For more information, see <http://code.google.com/p/shredmate/>

 ShredMate is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 ShredMate is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with ShredMate.  If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/

#ifndef SHREDMATEENGINE_H
#define SHREDMATEENGINE_H

#include <QObject>

#include "shredmateengine_global.h"

#include <QtMultimedia/qaudio.h>

#include "marker.h"
#include "range.h"

class AbstractPCMBuffer;
class AbstractPlaybackControl;
class PCMGenerator;
class QAudioOutput;

class SHREDMATEENGINESHARED_EXPORT ShredmateEngine : public QObject
{
    Q_OBJECT

public:
    ShredmateEngine(QObject* parent = 0);
    virtual ~ShredmateEngine();

    void setPCMBuffer(const AbstractPCMBuffer* pcmBuffer);

    QList<Marker> markers() const;
    void setMarkers(QList<Marker> markers);

    QList<Range> ranges() const;
    void setRanges(QList<Range> ranges);

    void setActiveRange(int index);
    int activeRange() const;

    bool isPlaying() const;

    void setPosition(qint64 position);
    qint64 position() const;
    qint64 bufferLength() const;

    void setLooping(bool looping);
    bool isLooping() const;

public slots:
    void play();
    void stop();
    void togglePause();

signals:
    void notify();

private slots:
    void handleStateChanged(QAudio::State state);

    private:
    const AbstractPCMBuffer* m_pcmBuffer;
    PCMGenerator* m_pcmGenerator;
    QAudioOutput* m_audioOutput;

    QList<Marker> m_markers;
    QList<Range> m_ranges;

    int m_activeRange;
    qint64 m_currentPosition;
};

#endif // SHREDMATEENGINE_H
